$def with (case, last_email, admins, pretty_print_date, prev_url=None, next_url=None)

$var title: $case.subject ($case.creator_username)

$ all = query_param("all", "false")
$ filter = query_param("filter", "new")

<script type="text/javascript">
window.q.push(function() {
    \$("#checkbox3").change(function() {
        \$("#textarea").val($:json_encode(last_email));
    });
});
</script>


<div id="contentHead">
    $:render_template("admin/menu", "/admin")
</div>

<div id="contentBody">

<form id="form1" name="form1" method="post" action="">
<table class="changeHistory" border="0" cellspacing="0" style="width: 100%; margin-top: -20px; border-top: 1px solid #eee;">
  <tr>
    <th colspan="2">
            <a href="/admin/support?all=$all&filter=$filter">Support</a> /
            <span class="black highlight"><b>$(case.caseid)</b></span>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
            <b>Status: $case.status</b>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
            Case created: $(datestr(case.created)), $(pretty_print_date(case.created))

        <div style="float: right; margin: 0;">
            $if prev_url:
                <a href="$prev_url" id="prev-case">&larr; Prev</a>
            $else:
                <span>&larr; Prev</span>
            | <a href="/admin/support?all=$all&filter=$filter">Home</a>
            $if next_url:
                | <a href="$next_url" id="next-case">Next &rarr;</a>
            $else:
                | <span>Next &rarr;</span>
        </div>
    </th>
  </tr>
  <tr>
    <td colspan="2" style="padding-left: 20px; background-color: #f5f5f5;">
        <span class="largest">$:format(case.description)</span>
    </td>
  </tr>
  <tr>
    <td colspan="2" style="padding-left: 20px;">

    $if (case.creator_name):
        <span class="black"><b>$(case.creator_name)</b></span>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
        $(case.creator_email)&nbsp;&nbsp;&bull;&nbsp;&nbsp;
        <a href="/admin/people/$(case.creator_username)">$(case.creator_username)</a>
    $else:
        <span class="black"><b>$(case.creator_email)</b></span>&nbsp;&nbsp;&bull;&nbsp;&nbsp;
        <span class="smaller">Not logged in</span> (<a href="/admin/people/$(case.creator_email)">$(case.creator_email)</a>)


    <br/><br/><span class="smaller">$(case.creator_useragent)</span></td>
  </tr>
  <tr>
    <td colspan="2" style="padding-left: 20px;">
        $if case.status != "closed":
            <div style="float: right; margin: 0;"><input type="submit" name="button" id="close2" value="CLOSE CASE" /></div>
        $else:
    	    <div style="float: right; margin: 0;"><input type="submit" name="button" id="close2" value="REOPEN CASE" /></div>

         <strong>$(case.subject)</strong>&nbsp;&nbsp;&bull;&nbsp;&nbsp;From <a href="$(case.url)">$(case.url)</a>&nbsp;&nbsp;&bull;&nbsp;&nbsp;<a href="/admin/support/$(case.caseno)">https://openlibrary.org/admin/support/$(case.caseno)</a>
    </td>
  </tr>
</table>

<h2>Case History</h2>

<table class="changeHistory" border="0" cellspacing="0" style="width: 100%; border-top: 1px solid #eee;">
  $for entry in case.history:
    <tr>
        <td style="width: 25%">
            <span class="black"><b>$(datestr(entry.at))</b></span> <span class="smaller">$(pretty_print_date(entry.at))</span>
            <br />
            $(entry.by)
        </td>
        <td>$:format(entry.text)</td>
    </tr>
</table>

<table style="width: 100%">
<tr>
<td style="width: 50%; vertical-align: top;">
    <h2>Send reply</h2>
    <p>To: <input name="email" type="text" id="email" value="$(case.creator_email)" size="35" /> </p>
    <p>
	<input name="quote_email" type="checkbox" id="checkbox3" /> <label for="checkbox3">Quote latest email?</label><br />
	<textarea class="markdown" name="casenote1" id="textarea" rows="10" style="width: 420px"></textarea>
    </p>
    <p><input type="submit" name="button" id="button3" value="SEND REPLY" /></p>
</td>
<td style="width: 50%; vertical-align: top;">
    <h2>Add Case Note/Re-assign</h2>
    <p>Assigned to:
    <select name="assignee" id="assignee">
	$for email,username,selected in admins:
	  $if selected:
	     <option selected="selected" value="$:email">$username</option>
          $else:
	     <option value="$:email">$username</option>
    </select>
    <p>Add Case Note:</p>
    <p><textarea class="markdown" name="casenote2" id="textarea2" rows="10" style="width: 420px"></textarea></p>
    <p><input type="submit" name="button" id="button" value="UPDATE" /></p>
</td>
</tr>
</table>

	$if case.status != "closed":
	   <p align="center"><input type="submit" name="button" id="close2" value="CLOSE CASE" /></p>
	$else:
	   <p align="center"><input type="submit" name="button" id="close2" value="REOPEN CASE" /></p>

</div>
</form>
